<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="课程id" prop="lessonId">
                <el-input v-model="queryParams.lessonId" placeholder="请输入课程id" clearable/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini">搜索</el-button>
            </el-form-item>
        </el-form>

<!--        <el-row :gutter="10" class="mb8">-->
<!--            <el-col :span="1.5">-->
<!--                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['stu:score:add']">新增-->
<!--                </el-button>-->
<!--            </el-col>-->
<!--            <el-col :span="1.5">-->
<!--                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['stu:score:edit']">修改-->
<!--                </el-button>-->
<!--            </el-col>-->
<!--            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--        </el-row>-->
        <TableCard>
            <el-table  :border="Global.tableShowBorder" v-loading="loading" :data="scoreList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center"/>
                <el-table-column label="学号" align="center" prop="code"/>
                <el-table-column label="姓名" align="center" prop="name"/>
                <el-table-column label="总分" align="center" prop="total"/>

    <!--                <el-table-column v-for="i in colList" :label="i" align="center" header-align="center">-->
    <!--                    <template slot-scope="scope">{{scope.row[i][index]}}</template>-->
    <!--                </el-table-column>-->

                <el-table-column align="center" v-for="(item, index) in colList" :key="index" :prop="item.prop" :label="item.label"></el-table-column>

            </el-table>
        </TableCard>
    </div>
</template>

<script>
import {lessonScoreTable} from "@/api/stu/score";

export default {
    name: "studentScore",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 学生成绩表格数据
            scoreList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                studentId: null,
                lessonId: null,
                pointId: null,
                score: null
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
            lessonId:null,
            colList:[],
            type:""
        };
    },
    created() {
        const lessonId = this.$route.params && this.$route.params.lessonId;
        const type = this.$route.query && this.$route.query.type;
        console.log("成绩类型："+type);
        console.log(lessonId);
        if(lessonId && type){
            this.lessonId = lessonId;
            this.type = type;
            this.getList();
        }
    },
    methods: {
        /** 查询学生成绩列表 */
        getList() {
            this.loading = true;
            lessonScoreTable(this.lessonId,this.type).then(response => {
                this.scoreList = response.data.listData;
                this.colList = response.data.colData;
                this.loading = false;
            });
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加学生成绩";
        },
    }
};
</script>
